package com.xwqiang.utils;

public class Resp<T>{

    private int code = 0;
    private String msg = "ok";
    private T data = null;

    private Resp(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Resp<T> success(){
        return new Resp<T>(0, "ok", null);
    }

    public static <T> Resp<T> success(T data){
        return new Resp<T>(0, "ok", data);
    }

    public static <T> Resp<T> success(String msg){
        return new Resp<T>(0, msg, null);
    }

    public static <T> Resp<T> success(String msg, T data){
        return new Resp<T>(0, msg, data);
    }

    public static <T> Resp<T> error(ErrCode errCode){
        return new Resp<T>(errCode.getCode(), errCode.getMsg(), null);
    }

    public static <T> Resp<T> error(int code,String msg){
        return new Resp<T>(code, msg, null);
    }

    public int getCode(){
        return code;
    }

    public String getMsg(){
        return msg;
    }

    public T getData(){
        return data;
    }
}